﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using WebUI.Helper;
namespace WebUI.Con.Admin
{
    public class CostController: Controller
    {
        [Common.Attributes.Skip]

        public ActionResult CostSubmit()
        {
            ViewData["CostClassID"] = OperateContext.Current.BLLSession.ICostClassBLL.GetListBy(s => s.CostClassID > 0).Select(s => new SelectListItem
            {

                Text = s.CostClassName,
                Value = s.CostClassID.ToString()

            }).ToList();
          
            return PartialView("CostSubmit");
        }

        public ActionResult CostAdd(Model.ViewModel.Cost c)
        {
            Model.Cost Addc=new Model.Cost();
            Addc.UserName=c.UserName;
            Addc.UserID = OperateContext.Current.Usr.UserID;
            Addc.ShfitID = OperateContext.Current.Shift.ShiftID;
            Addc.CostClassID = c.CostClassID;
            Addc.CostDetail = c.CostDetail;
            Addc.CostAmount = c.CostAmount;
            Addc.CostTime = DateTime.Now;
            int p = OperateContext.Current.BLLSession.ICostBLL.Add(Addc);
            if (p == 1)
            { return Content("ok"); }
            else
            {
                return Content("Error"); 
            }
        }

        [Common.Attributes.Skip]
        public ActionResult CostList()
        {
            DateTime PreCheckoutTime = OperateContext.Current.BLLSession.ICheckoutBLL.GetListBy(s => s.CheckoutID > 0, s => s.CheckoutID, false).Select(s => s.CheckoutTime ?? DateTime.Now).ToList().FirstOrDefault();

            var C_L = OperateContext.Current.BLLSession.ICostBLL.GetListBy(s => (s.CostTime ?? DateTime.Now).CompareTo(PreCheckoutTime) > 0).Select(s => new Model.ViewModel.CostList()
            {
                AccuntUserName = s.UserName,
                CostClassName = s.CostClass.CostClassName,
                CostTime = (s.CostTime ?? DateTime.Now).ToString("yy年MM月dd日hh时mm分"),
                CostAmount = (s.CostAmount ?? 0).ToString("0.00"),
                ShfitName = s.Shift.ShiftName,
                CostDetail = s.CostDetail,
                UserName = s.UserDB.NickName

            }).ToList();
            return PartialView("CostList", C_L);
        }
    }
}
